package com.mcr.graduateprogram.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.mcr.graduateprogram.bean.Clientele;
import com.mcr.graduateprogram.common.R;
import com.mcr.graduateprogram.service.IClienteleService;
import com.mcr.graduateprogram.service.IPhotoUpload;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author graduateprogram
 * @since 2023-02-25
 */
@Api(tags = "客户相关接口")
@CrossOrigin
@RestController
@RequestMapping("/graduateprogram/clientele")
public class ClienteleController {
    @Autowired
    private IClienteleService iClienteleService;
    @Value("${qiniu.clientele}")
    private String clienteleUrl;
    @Autowired
    private IPhotoUpload iPhotoUpload;
    @GetMapping("getPage")
    @ApiOperation(value = "分页查询客户账号")
    public R getPage(@RequestParam(value = "page")Integer page,
                     @RequestParam(value = "pageSize")Integer pageSize,
                     @RequestParam(value = "name",required = false)String name){
        Page<Clientele> clientelePage=iClienteleService.getPage(page,pageSize,name);
        return R.success(clientelePage);
    }
    @ApiOperation(value = "修改用户信息")
    @PostMapping("updateClientele")
    public R updateClientele(@RequestBody Clientele clientele){
        return R.success(iClienteleService.updateClienteleById(clientele));
    }
    @ApiOperation(value = "用户注册")
    @PostMapping("registerClientele")
    public R registerClientele(@RequestBody Clientele clientele){
        return R.success(iClienteleService.registerClientele(clientele));
    }
    @ApiOperation(value = "用户登录")
    @PostMapping("loginClientele")
    public R loginClientele(@RequestBody Clientele clientele){
        return R.success(iClienteleService.loginClientele(clientele));
    }
    @ApiOperation(value = "用户头像上传")
    @PostMapping("uploadClientelePhoto")
    public R uploadClientelePhoto(@RequestPart MultipartFile photo){
        return R.success(iPhotoUpload.photoUpload(photo,clienteleUrl));
    }
    @ApiOperation(value = "查询所有用户")
    @GetMapping("getAll")
    public R getAll(){
        return R.success(iClienteleService.list());
    }
}
